package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.Requesturl;
import com.example.entity.Role;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RequesturlMapper extends BaseMapper<Requesturl> {

    @Select("SELECT\n" +
            "\tru.*,\n" +
            "\tr.id AS rid,\n" +
            "\tr.`name` AS rname,\n" +
            "\tr.name_zh AS rnameZh \n" +
            "FROM\n" +
            "\tt_requesturl AS ru,\n" +
            "\tt_requesturl_role AS rur,\n" +
            "\tt_role AS r \n" +
            "WHERE\n" +
            "\tru.id = rur.mid \n" +
            "\tAND r.id = rur.rid \n" +
            "ORDER BY\n" +
            "\tru.id")
    List<Requesturl> getUrlWithRole();

    @Select("SELECT \n" +
            "r.id, r.`name`, r.name_zh \n" +
            "FROM\n" +
            "t_requesturl AS ru,t_requesturl_role AS rur,t_role AS r \n" +
            "WHERE\n" +
            "ru.id = rur.mid AND r.id = rur.rid\n" +
            "AND ru.id = #{id}")
    List<Role> getRoles(int id);
}
